package com.emmy.walnut.dao;

import android.arch.persistence.room.Dao;
import android.arch.persistence.room.Insert;
import android.arch.persistence.room.Query;
import android.arch.persistence.room.Update;

import com.emmy.walnut.model.Record;
import com.emmy.walnut.model.RecordWithPeriod;
import com.emmy.walnut.model.User;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName RecordDao
 * @Description TODO
 * @Author zhouxuan
 * @Date 2020/02/05 10:38
 * @Version 1.0
 */
@Dao
public interface RecordDao {
    @Insert
    long insert(Record record);

    @Update
    void update(Record record);

    @Query("select * from Record where username = :username and endTimestamp = -1")
    List<Record> getUndoneRecordWithUser(String username);

    @Query("select * from Record " +
            "where username = :username and startTimestamp>:startTimestamp and startTimestamp<:endTimestamp " +
            "and endTimestamp!=-1 order by startTimestamp desc")
    List<Record> getRecordWithPeriod(String username, long startTimestamp, long endTimestamp);

    @Query("select * from Record " +
            "where username = :username and startTimestamp>:startTimestamp and startTimestamp<:endTimestamp " +
            "and endTimestamp!=-1 and labelName = :labelName order by startTimestamp desc")
    List<Record> getRecordWithPeriodAndLabel(String username,
                                             String labelName, long startTimestamp, long endTimestamp);

    @Query("select * from Record " +
            "where username = :username and startTimestamp>:startTimestamp and startTimestamp<:endTimestamp " +
            "and endTimestamp!=-1 and labelName in (:labelNames)  order by startTimestamp")
    List<Record> getRecordWithPeriodAndLabelsOrderByDate(String username,
                                                         List<String> labelNames, long startTimestamp, long endTimestamp);

    @Query("select * from Record " +
            "where username = :username and startTimestamp>:startTimestamp and startTimestamp<:endTimestamp " +
            "and endTimestamp!=-1 and labelName in (:labelNames)  order by labelName")
    List<Record> getRecordWithPeriodAndLabelsOrderByLabel(String username,
                                                          List<String> labelNames, long startTimestamp, long endTimestamp);

}
